package com.lc.afbx.activity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.lc.afbx.BaseApplication;
import com.lc.afbx.R;
import com.lc.afbx.conn.GetApiFeedbackAdd;
import com.lc.afbx.util.MyToast;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

/**
 * Created by Administrator on 2016/5/20.
 */
public class FeedbackActivity extends BaseActivity implements View.OnClickListener {

    private TextView feedback_text_count_tv;
    private EditText feedback_content_et;

    private GetApiFeedbackAdd getApiFeedbackAdd = new GetApiFeedbackAdd(new AsyCallBack<GetApiFeedbackAdd.Info>() {

        @Override
        public void onSuccess(String toast, int type, GetApiFeedbackAdd.Info info) throws Exception {

            UtilToast.show(context, "提交成功");
            finish();

        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            UtilToast.show(context, toast);

        }
    });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feedback);

        feedback_text_count_tv = ((TextView) findViewById(R.id.feedback_text_count_tv));
        feedback_content_et = ((EditText) findViewById(R.id.feedback_content_et));

        feedback_content_et.addTextChangedListener(new TextWatcher() {

            private CharSequence temp = "";
            private final int charMaxNum = 200;

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                temp = s;
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

                feedback_text_count_tv.setText(temp.length() + "");
            }

            @Override
            public void afterTextChanged(Editable s) {

                if (temp.length() == charMaxNum) {
                    MyToast.showToast("限制输入200字", context);
                }
            }
        });
    }


    @Override
    public void onClick(View view) {


        switch (view.getId()) {

            case R.id.back:
                finish();
                return;

            case R.id.feedback_submit_bt:

                String contentStr = feedback_content_et.getText().toString().trim();

                if (TextUtils.isEmpty(contentStr)) {
                    UtilToast.show(this, "意见不能为空");
                    return;
                }

                getApiFeedbackAdd.userid = BaseApplication.BasePreferences.readUserId();
                getApiFeedbackAdd.content = contentStr;
                getApiFeedbackAdd.execute(context);
                return;
        }


    }


}
